package com.sz.app.edi.service.receive.rest;

import com.sz.common.base.utils.BeanUtils;
import com.sz.biz.logistics.ord.service.OrdOrderService;
import com.sz.biz.logistics.ord.dto.OrdOrderDto;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;

//@Component
public class OrdOrderProcessor implements Processor {
    @Autowired
    private OrdOrderService ordOrderService;
    @Override
    public void process(Exchange exchange) throws Exception {
        SecurityManager securityManager = (SecurityManager) BeanUtils.getBean("securityManager");
        SecurityUtils.setSecurityManager(securityManager);
        Subject subject = SecurityUtils.getSubject();
        if (!subject.isAuthenticated()) {
            UsernamePasswordToken token = new UsernamePasswordToken("logistics", "123123");
            subject.login(token);
        }
        OrdOrderDto dto = (OrdOrderDto) exchange.getIn().getBody();
        ordOrderService.saveOrderDto(dto);
    }
}